package com.ars.website;

import com.ars.db.DBTools;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;

import javax.swing.*;

public class AddWebsiteController {
    @FXML
    private TextField tfWebsiteName;
    @FXML
    private TextField tfPassword;
    @FXML
    private TextField tfCity;
    @FXML
    private TextField tfAddress;


    @FXML
    public void addButtonAction() {
        String WebsiteName = tfWebsiteName.getText().trim();
        String Password = tfWebsiteName.getText().trim();
        String City = tfWebsiteName.getText().trim();
        String Address = tfWebsiteName.getText().trim();
        if (!WebsiteName.equals("") && !Password.equals("") && !City.equals("") && !Address.equals("")) {
            DBTools p = new DBTools();
            String sql = "insert into website values(NULL,'" + WebsiteName + "','" + Password + "','" + City + "','" + Address + "','3')";
            int t = p.update(sql);
            if (t != 0) {
                JOptionPane.showMessageDialog(null, "添加成功！");
            } else {
                JOptionPane.showMessageDialog(null, "添加失败！");
            }
        } else {
            JOptionPane.showMessageDialog(null,"请将表单填写完整！");
        }

    }

    @FXML
    public void cancelButtonAction() {
        tfAddress.clear();
        tfCity.clear();
        tfPassword.clear();
        tfWebsiteName.clear();
    }
}
